<template>
  <div class="app-container">
    <!--站点数据-->
    <el-form
      :model="queryParams"
      ref="queryForm"
      :inline="true"
      label-width="90px"
    >
      <el-form-item label="订单号" prop="tradeNo">
        <el-input
          v-model="queryParams.tradeNo"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
         <el-form-item label="订单类型" prop="status">
        <el-select
          v-model="queryParams.status"
          placeholder="状态"
          clearable
          size="small"
        >
          <el-option :key="" :label="'全部'" :value="null" />
          <el-option
            v-for="dict in orderStatusOptions"
            :key="dict.key"
            :label="dict.value"
            :value="dict.key"
          />
        </el-select>
      </el-form-item>
       <el-form-item label="到账时间" prop="time">
        <el-date-picker
          v-model="queryParams.time"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="选择校区" prop="schoolId">
        <el-select
          v-model="queryParams.schoolId"
          placeholder="请选择"
          clearable
          filterable
          size="small"
          @keyup.enter.native="handleQuery"
        >
          <el-option :key="" :label="'全部'" :value="null" />
          <el-option
            v-for="dict in schoolOptions"
            :key="dict.key"
            :label="dict.value"
            :value="dict.key"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="跑腿员类型" prop="runnerType">
        <el-select
          v-model="queryParams.runnerType"
          placeholder="类型"
          clearable
          size="small"
        >
          <el-option :key="" :label="'全部'" :value="null" />
          <el-option
            v-for="dict in runnerTypeOptions"
            :key="dict.key"
            :label="dict.value"
            :value="dict.key"
          />
        </el-select>
      </el-form-item>
      
      <el-form-item label="跑腿员手机" prop="runnerTel">
        <el-input
          v-model="queryParams.runnerTel"
          placeholder="请输入"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>

   

      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
      </el-form-item>
    </el-form>

    <el-table
      v-loading="loading"
      :data="tabelList"
      @selection-change="handleSelectionChange"
    >
      <!-- <el-table-column type="selection" width="50" align="center" /> -->
      <el-table-column label="序号" type="index" align="center">
        <template slot-scope="scope">
          <span>{{
            (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
          }}</span>
        </template>
      </el-table-column>
      <el-table-column label="订单号" align="center" prop="no" />
      <el-table-column label="来源订单" align="center" prop="orderNo" />
      <el-table-column label="手机号" align="center" prop="tel" />
      <el-table-column label="类型" align="center" prop="runnerTypeName" />
      <el-table-column label="所属校区" align="center" prop="schoolName" />
      <el-table-column label="订单类型" align="center" prop="typeName" />
      <el-table-column label="分成比例" align="center" prop="ratio" />
      <el-table-column label="收入" align="center" prop="income" />
      <el-table-column label="结算时间" align="center" prop="createTime" />
      <el-table-column label="到账时间" align="center" prop="endTime" />
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
  </div>
</template>

<script>
import {
  listOrder,
  listOrderCancel,
  listOrderOption,
} from "@/api/pt/commission";
import { runnerOption } from "@/api/pt/runner.js";
import { areajson } from "@/utils/area.js";
/* 订单流程。 1.待支付 2.待接单 3.未取货 4.已取货 5.已送达 6.待评价 7完成
0123456 */
export default {
  name: "Cuser",
  components: {},
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 用户表格数据
      tabelList: null,
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 已有校区所在城市数据
      ownCity: [],
      // 已有下拉
      schoolOptions: [],
      siteOptions: [],
      runnerTypeOptions: [],
      orderStatusOptions: [],
      // 城市数据
      cityOptions: areajson,
      // 表单参数
      form: {},
      //详情打开
      detailOpen: false,
      listDetail: {
        order: {},
        runner: {},
        user: {},
      },

      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        runnerName: undefined,
        runnerTel: undefined,
        runnerType: undefined,
        schoolId: undefined,
        serviceType: undefined,
        siteId: undefined,
        tradeNo: undefined,
        runnerTel: undefined,
        status: "",
        time: "",
      },
      // 表单校验
      rules: {
        name: [
          { required: true, message: "站点名称不能为空", trigger: "blur" },
        ],
        schoolId: [{ required: true, message: "请选择校区", trigger: "blur" }],
        address: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
        time: [{ required: true, message: "请选择时间", trigger: "blur" }],
        email: [
          { required: true, message: "邮箱地址不能为空", trigger: "blur" },
          {
            type: "email",
            message: "'请输入正确的邮箱地址",
            trigger: ["blur", "change"],
          },
        ],
        phone: [
          { required: true, message: "手机号码不能为空", trigger: "blur" },
          {
            pattern: /^1[3|4|5|6|7|8|9][0-9]\d{8}$/,
            message: "请输入正确的手机号码",
            trigger: "blur",
          },
        ],
      },
    };
  },
  computed: {},
  created() {
    this.getList();
    runnerOption().then((response) => {
      this.runnerStatusOptions = response.data.state;
      this.runnerTypeOptions = response.data.type;
    });
    listOrderOption().then((response) => {
      this.schoolOptions = response.data.school;
      this.siteOptions = response.data.site;
      this.runnerTypeOptions = response.data.runnerType;
      this.orderStatusOptions = response.data.type;
    });
  },
  methods: {
    statusClass(e) {
      /* 订单流程。 1.待支付 2.待接单 3.未取货 4.已取货 5.已送达 6.待评价 7完成
          0123456*/
      let color = "";
      switch (e) {
        case 0:
          color = "rgb(244,84,84)";
          break;
        case 1:
          color = "rgb(230,35,16)";
          break;
        case 2:
          color = "rgb(27,154,204)";
          break;
        case 3:
          color = "rgb(27,154,204)";
          break;
        case 4:
          color = "rgb(0,215,255)";
          break;
        case 5:
          color = "rgb(27,255,204)";
          break;
        case 6:
          color = "rgb(12,208,62)";
          break;
        default:
          color = "rgb(208,197,197)";
      }
      return color;
    },
    /* 用户状态 */
    runnerTypeNameStatus(str) {
      if (str === 0) {
        return "普通";
      } else if (str === 1) {
        return "平台";
      } else if (str === "0") {
        return "普通";
      } else if (str === "1") {
        return "平台";
      } else {
        return "";
      }
    },
    /* 用户状态 */
    cuserState(str) {
      if (str === 0) {
        return "正常";
      } else if (str === 1) {
        return "冻结中";
      } else if (str === 2) {
        return "已拉黑";
      } else if (str === 3) {
        return "已注销";
      }
    },
    /** 查询用户列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams)
      listOrder(
        this.addDateRange2(this.queryParams, "createTimeStart", "createTimeEnd")
      ).then((response) => {
        this.tabelList = response.data.list;
        this.total = response.data.total;
        this.loading = false;
      });
    },
    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
      this.queryParams.deptId = data.id;
      this.getList();
    },
    // 用户状态修改
    handleStatusChange(row) {
      let text = row.status === 0 ? "启用" : "关闭";
      this.$confirm("确认要" + text + '"' + row.name + '"吗?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(function () {
          row.time = [new Date(row.startTime), new Date(row.endTime)];
          return addSchool(row);
        })
        .then(() => {
          this.msgSuccess(text + "成功");
        })
        .catch(function () {
          row.status = row.status === "0" ? "1" : "0";
        });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.resetForm("form");
      this.form = {
        id: undefined,
        schoolId: undefined,
        name: undefined,
        city: undefined,
        status: undefined,
        address: undefined,
        siteDescribe: undefined,
        personInCharge: undefined,
        mobile: undefined,
        personInCharge2: undefined,
        mobile2: undefined,
        time: undefined,
      };
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.dateRange = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
   
    // 获取当前选中校区所在城市
    selectSchool(val) {
      this.schoolOptions.map((item) => {
        if (item.id === val) this.form.city = item.city;
      });
    },
  },
};
</script>

<style type="text/css">
.dian {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: #999;
  margin-right: 6px;
}
.typeyuan {
  width: 25px;
  height: 25px;
  line-height: 25px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 6px;
  border: 1px solid #999;
  vertical-align: middle;
  text-align: center;
}
</style>
